/*
 * Created on 2004-12-29
 */


package com.haoxi.gateway.util;
import sun.misc.BASE64Decoder;

/**
 * @author Jason
 * 
 * Base64������
 */
public class Base64Util {
    //ȡBase64����
    public static String getBASE64(String source) {
        if (source == null)
            return null;
        return (new sun.misc.BASE64Encoder()).encode(source.getBytes());
    }

    //��Base64���뻹ԭ
    public static String getFromBASE64(String dest) {
        if (dest == null)
            return null;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(dest);
            return new String(b);
        } catch (Exception e) {
            return null;
        }
    }
    
    public static String getBASE64(byte[] source) {
        if (source == null)
            return null;
        return (new sun.misc.BASE64Encoder()).encode(source);
    }
    
    public static void main(String[] args){
        //String str=args[0];
//        String str="309900";
//        System.out.println("351376="+getBASE64("351376"));
//        System.out.println("10000="+getBASE64("10000"));
//        System.out.println("351379="+getBASE64("351379"));
//        System.out.println("351383="+getBASE64("351383"));
//        System.out.println("351386="+getBASE64("351386"));
//        System.out.println("MzEwMDEzOjIx="+getFromBASE64("MzEwMDEzOjIx"));
//        
        
		String str = "ODE2NiBUUEJZ";
		System.out.println(str + "="+getFromBASE64(str));
		
		String sss = "13751525537500��ϲ���Ϊͼ���ܿ�ӭ�´�������Ѽ������ֵ������û�����Ϊ��׼�������缤��Ů������ĺͼ����԰����䣬�ظ�P��֤����ա�";
		System.out.println("sss base64="+getBASE64(sss));
		
		String s1 = "MTM3NjA5MTk5NTAxMjAwQjA1MDQwQjg0MjNGMDAwMDMwODA4MDYyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMDIwMjAyMA==";
		System.out.println("s1 ="+getFromBASE64(s1));
		
		
    }

}